<?php
/*
 * 内链管理 后台
 */
class action extends app
{
	public function display()
	{
		$action = $this->routes->url(3);
		if(!method_exists($this,$action))
		$action = "manage";
		$this->$action();
		exit;
	}

	private function manage(){
		$ListAll=$this->inlink->getAll();
		$this->tpl->assign("FormTitle",'内链管理列表');
		$this->tpl->assign("FormAction",MyAppUrl."inlink-add");
		$this->tpl->assign('ListAll',$ListAll);
		$this->tpl->display('inlink_list');	
	}
	
	private function add(){
		$_SESSION['input_token'] = md5(rand(100,1000));
		$this->tpl->assign("input_token",$_SESSION['input_token']);
		$this->tpl->assign("FormTitle",'新增内部链接');
		$this->tpl->assign("FormAction",MyAppUrl."inlink-save");
		$this->tpl->display('inlink_form');
	}


	private function save(){
		if($_SESSION['input_token']!="" && $_SESSION['input_token']==$_POST['input_token']){
			$_SESSION['input_token']='';
			$dsw =$_POST['dsw'];
			$dsw['endtime']=time();
			$dsw['enduser']=$_SESSION['tinwinsession']['uid'];
			$dsw['addtime']=time();
			$dsw['adduser']=$_SESSION['tinwinsession']['uid'];
			if($dsw){
				$this->inlink->save($dsw);
				$message = array(
					'CodeType' =>200,
					"message" => "添加成功",
					"callbackType" => 'forward',
					"forwardUrl" => MyAppUrl."inlink-manage"	
				);
				$this->G->R($message);
			}
		}
	}
	
	private function edit(){
		$IntID=$this->routes->get('id');
		$ListOne=$this->inlink->getOneLinkByID($IntID);
		$this->tpl->assign("ListOne",$ListOne);
		$_SESSION['input_token'] = md5(rand(100,1000));
		$this->tpl->assign("input_token",$_SESSION['input_token']);
		$this->tpl->assign("FormTitle",'编辑链接');
		$this->tpl->assign("FormAction",MyAppUrl."inlink-update&id=$IntID");
		$this->tpl->display('inlink_form');	
	}

	private function update(){
		if($_SESSION['input_token']!="" && $_SESSION['input_token']==$_POST['input_token']){
			$_SESSION['input_token']='';
			$dsw =$_POST['dsw'];
			$IntID=$this->routes->get('id');
			if($dsw){
				$this->inlink->update($dsw,array('id'=>$IntID));
				$message = array(
					'CodeType' =>200,
					"message" => "链接修改成功",
					"callbackType" => 'forward',
					"forwardUrl" => MyAppUrl."inlink-manage"	
				);
				$this->G->R($message);
			}
		}
	}
	
	
	private function isview(){
		$IntID=$this->routes->get('id');
		echo $this->inlink->isview($IntID);
	}
	
	private function del(){
		$IntID=$this->routes->get('id');
		$this->inlink->del($IntID);
		$message = array(
			'statusCode' =>200,
			"message" => "删除成功",
			"callbackType" =>'forward',
			"forwardUrl" =>MyAppUrl.'inlink'
		);
		$this->G->R($message);
	}
}
?>
